package com.frostmourne.loreoriginex.utils;

import com.frostmourne.loreoriginex.LoreOriginEX;
import com.frostmourne.loreoriginex.objects.LoreOrigin;
import com.frostmourne.loreoriginex.objects.LoreOriginData;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;

public class LangUtils {

    public static void send(LivingEntity livingEntity, String lang){

        if (LoreOriginEX.getLangConfig() == null || getMess(lang).equalsIgnoreCase("none")){
            return;
        }
        livingEntity.sendMessage(
                getMess("Prefix") + getMess(lang)
        );
    }

    private static String color(String mess){
        return mess.replace("&","§");
    }

    public static String getMess(String path){
        String mess = "none";
        FileConfiguration config = LoreOriginEX.getLangConfig();
        if (
                config.getKeys(false).contains(path) || !config.getString(path).equalsIgnoreCase("none")
        ){
            mess = color(config.getString(path));
        }
        return mess;
    }

    public static void sendStats(LivingEntity livingEntity ,LoreOriginData loreOriginData){
        switch (loreOriginData.getLoreOrigin().getName().toLowerCase()){

            case "health":
                livingEntity.sendMessage("§a§l" + loreOriginData.getLoreOrigin().getKeys().get(0)
                + ": §c§l" + loreOriginData.getValues().get(0));
                break;

            case "damage":
                livingEntity.sendMessage("§a§l" + loreOriginData.getLoreOrigin().getKeys().get(0)
                + ": §c§l" + (loreOriginData.getValues().size() == 1 ? loreOriginData.getValues().get(0) : loreOriginData.getValues().get(0) + " - " + loreOriginData.getValues().get(1)));
                break;

            default:
                break;
        }
    }

}
